/**
 * 作者: wgx
 * 日期: 2025-03-05 17:54:04
 * 备注: 子嗣联姻的指定联姻
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserMarryApplyModel extends BaseModel implements Model {
    public static final String LISTKEY = "user_id.child_id_from";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = true;// 是否需要额外的有序列表

    protected long id; // 数据库ID
    protected long userId; // 玩家id
    protected long childIdFrom; // 发起的子嗣id
    protected long userIdFrom; // 发起的玩家id
    protected int sex; // 性别 (0女1男)
    protected long addTime; // 发布时间

    public void reset() {
    }

    protected String getKey() {
        return "UserMarryApply." + userId + "." + childIdFrom;
    }

    protected String getListKey() {
        return "UserMarryApply." + userId;
    }

    protected String getListItemKey() {
        return childIdFrom + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_marry_apply"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 数据库ID
        obj.put("userId", userId); // 玩家id
        obj.put("childIdFrom", childIdFrom); // 发起的子嗣id
        obj.put("userIdFrom", userIdFrom); // 发起的玩家id
        obj.put("sex", sex); // 性别 (0女1男)
        obj.put("addTime", addTime); // 发布时间
        return obj;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public long getChildIdFrom() {
        return childIdFrom;
    }

    public void putChildIdFrom(long childIdFrom) {
        if (this.childIdFrom != childIdFrom) {
            this.childIdFrom = childIdFrom;
            updateRedisHashField(getKey(), "childIdFrom", this.childIdFrom);
        }
    }

    public void addChildIdFrom(long value) {
        this.childIdFrom += value;
        updateRedisHashField(getKey(), "childIdFrom", this.childIdFrom);
    }

    public long getUserIdFrom() {
        return userIdFrom;
    }

    public void putUserIdFrom(long userIdFrom) {
        if (this.userIdFrom != userIdFrom) {
            this.userIdFrom = userIdFrom;
            updateRedisHashField(getKey(), "userIdFrom", this.userIdFrom);
        }
    }

    public void addUserIdFrom(long value) {
        this.userIdFrom += value;
        updateRedisHashField(getKey(), "userIdFrom", this.userIdFrom);
    }

    public int getSex() {
        return sex;
    }

    public void putSex(int sex) {
        if (this.sex != sex) {
            this.sex = sex;
            updateRedisHashField(getKey(), "sex", this.sex);
        }
    }

    public void addSex(int value) {
        this.sex += value;
        updateRedisHashField(getKey(), "sex", this.sex);
    }

    public long getAddTime() {
        return addTime;
    }

    public void putAddTime(long addTime) {
        if (this.addTime != addTime) {
            this.addTime = addTime;
            updateRedisHashField(getKey(), "addTime", this.addTime);
        }
    }

    public void addAddTime(long value) {
        this.addTime += value;
        updateRedisHashField(getKey(), "addTime", this.addTime);
    }

}